// components/c-image-upload/c-image-upload.js
Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    userWidth: 200,
    use:[
      "https://c-ssl.dtstatic.com/uploads/blog/202211/06/20221106202737_1d1ba.thumb.1000_0.jpeg",
      "https://c-ssl.dtstatic.com/uploads/blog/202211/06/20221106202737_1d1ba.thumb.1000_0.jpeg",
      "https://c-ssl.dtstatic.com/uploads/blog/202211/06/20221106202737_1d1ba.thumb.1000_0.jpeg",
      "https://c-ssl.dtstatic.com/uploads/blog/202211/06/20221106202737_1d1ba.thumb.1000_0.jpeg"
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    setUserWidth:function(width){
      this.setData({
        userWidth:width
      })
    },
    remove:function(e){
      let index=e.target.dataset.index
      let newUse=this.data.use;
      newUse.splice(index,1)
      this.setData({
        use:newUse
      })
    },
    add:function(){
      let newUse=this.data.use.concat(["https://c-ssl.dtstatic.com/uploads/blog/202211/06/20221106202737_1d1ba.thumb.1000_0.jpeg"])
      this.setData({
        use:newUse
      })
    }
  },
  lifetimes: {
    attached: function () {
      var _this=this
      let res= this.createSelectorQuery().select(".obj").boundingClientRect(function (rect) {
        if(rect === null){
          return 
        }
        _this.setUserWidth(rect.width)
      }).exec()
    },
  }

})